<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
<h1>支付成功！</h1>
<p><span>5</span>秒后返回上一页，<button class="btn">立即返回</button></p>

<script>
var btn = document.querySelector('.btn');
btn.onclick = function (){
    // 返回上一页
    // history.back();
    history.go(-1);
}

// 5秒倒计时
var span = document.querySelector('span');
var time = 5;
setInterval(function (){
    time--;
    span.innerText = time;
    // 临界值判断
    // if (time === 0) {
    if (!time) {
        // 返回上一页
        // history.back();
        history.go(-1);
    }
},1000)

</script>
</body>
</html>